package com.wn.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * 定向模式配置
 */
@Configuration
public class DirectModelConfig {
    //创建一个交换机
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("direct.exchange");
    }
    //创建两个队列
    @Bean
    public Queue directQueue1() {
        return new Queue("direct.queue1");
    }
    @Bean
    public Queue directQueue2() {
        return new Queue("direct.queue2");
    }
    //将队列绑定到交换机
    @Bean
    public Binding directBinding1(Queue directQueue1, DirectExchange directExchange) {
        //with：指定路由键
        return BindingBuilder.bind(directQueue1).to(directExchange).with("gz");
    }
    @Bean
    public Binding directBinding2(Queue directQueue2, DirectExchange directExchange) {
        //with：指定路由键
        return BindingBuilder.bind(directQueue2).to(directExchange).with("sz");
    }
}